﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;

namespace Super_Wall_Breaker.Sources.GameEngine
{
    public class GlobalConfiguration
    {
        // Singleton 
        private static GlobalConfiguration _configuration;
         
        // Screen default configuration
        public const int DEFAULT_SCREEN_WIDTH = 1280;
        public const int DEFAULT_SCREEN_HEIGHT = 720;
        public const bool DEFAULT_IS_FULLSCREEN = true;
        public const bool DEFAULT_VSYNC_ACTIVATED = false;

        // GamePad default Configuration
        public const Buttons DEFAULT_RIGHT_BUTTON = Buttons.LeftThumbstickRight;
        public const Buttons DEFAULT_LEFT_BUTTON = Buttons.LeftThumbstickLeft;
        public const Buttons DEFAULT_PAUSE_BUTTON = Buttons.Start;

        // KeyBoard default Configuration
        public const Keys DEFAULT_PAUSE_KEY = Keys.Space;

        // Player1 KeyBoard default Configuration
        public const Keys DEFAULT_PLAYER1_RIGHT_KEY = Keys.Right;
        public const Keys DEFAULT_PLAYER1_LEFT_KEY = Keys.Left;

        // Player2 KeyBoard default Configuration
        public const Keys DEFAULT_PLAYER2_RIGHT_KEY = Keys.Z;
        public const Keys DEFAULT_PLAYER2_LEFT_KEY = Keys.A;

        // Player3 KeyBoard default Configuration
        public const Keys DEFAULT_PLAYER3_RIGHT_KEY = Keys.Y;
        public const Keys DEFAULT_PLAYER3_LEFT_KEY = Keys.T;

        // Player4 KeyBoard default Configuration
        public const Keys DEFAULT_PLAYER4_RIGHT_KEY = Keys.P;
        public const Keys DEFAULT_PLAYER4_LEFT_KEY = Keys.O;

        // Ball default Configuration
        public const float DEFAULT_BALL_SPEED = 0.15f; // pixel per ms
        public const float DEFAULT_SPEED_INCREMENT = 15; // in percent
        public const float DEFAULT_MAX_SPEED_INCREMENT = 200; // in percent

        // Bat default configuration 
        public const float DEFAULT_BAT_SPEED = 0.8f; // pixel per ms
        public const int DEFAULT_BAT_SPACING = 16; //pixels

        //Brick default configuration
        public const int BRICK_TEXTURE_HEIGHT = 26;
        public const int BRICK_TEXTURE_WIDTH = 63;
        public const int DEFAULT_BRICK_MAX_LIFE = 5;

        // Wall breaker spritesheet
        public const string DEFAULT_SPRITE_SHEET = "image_spriteSheet";
        public const int BAT_TEXTURE_HEIGHT = 17;
        public const int BAT_TEXTURE_WIDTH = 126;

        // Screen configuration
        private int _screenWidth = GlobalConfiguration.DEFAULT_SCREEN_WIDTH;
        private int _screenHeight = GlobalConfiguration.DEFAULT_SCREEN_HEIGHT;
        private bool _isFullscreen = GlobalConfiguration.DEFAULT_IS_FULLSCREEN;
        private bool _vSyncActivated = GlobalConfiguration.DEFAULT_VSYNC_ACTIVATED;

        // Controls using configuration
        private bool gamepadOneIsUsed = false;
        private bool gamepadTwoIsUsed = false;
        private bool gamepadThreeIsUsed = false;
        private bool gamepadFourIsUsed = false;

        private bool keyboardBindingOneIsUsed = false;
        private bool keyboardBindingTwoIsUsed = false;
        private bool keyboardBindingThreeIsUsed = false;
        private bool keyboardBindingFourIsUsed = false;

        public bool GamePadOneIsUsed
        {
            get { return this.gamepadOneIsUsed; }
            set { this.gamepadOneIsUsed = value; }
        }

        public bool GamePadTwoIsUsed
        {
            get { return this.gamepadTwoIsUsed; }
            set { this.gamepadTwoIsUsed = value; }
        }

        public bool GamePadThreeIsUsed
        {
            get { return this.gamepadThreeIsUsed; }
            set { this.gamepadThreeIsUsed = value; }
        }

        public bool GamePadFourIsUsed
        {
            get { return this.gamepadFourIsUsed; }
            set { this.gamepadFourIsUsed = value; }
        }

        public bool KeyboardBindingOneIsUsed
        {
            get { return this.keyboardBindingOneIsUsed; }
            set { this.keyboardBindingOneIsUsed = value; }
        }

        public bool KeyboardBindingTwoIsUsed
        {
            get { return this.keyboardBindingTwoIsUsed; }
            set { this.keyboardBindingTwoIsUsed = value; }
        }

        public bool KeyboardBindingThreeIsUsed
        {
            get { return this.keyboardBindingThreeIsUsed; }
            set { this.keyboardBindingThreeIsUsed = value; }
        }

        public bool KeyboardBindingFourIsUsed
        {
            get { return this.keyboardBindingFourIsUsed; }
            set { this.keyboardBindingFourIsUsed = value; }
        }

        private GlobalConfiguration() { }

        /// <summary>
        /// Return the configuration singleton.
        /// </summary>
        public static GlobalConfiguration Configuration
        {
            get
            {
                if (GlobalConfiguration._configuration == null)
                {
                    GlobalConfiguration._configuration = new GlobalConfiguration();
                }

                return GlobalConfiguration._configuration;                
            }
        }

        public int ScreenWidth
        {
            get { return this._screenWidth; }
            set { this._screenWidth = value; }
        }

        public int ScreenHeight
        {
            get { return this._screenHeight; }
            set { this._screenHeight = value; }
        }

        public bool IsFullscreen
        {
            get { return this._isFullscreen; }
            set { this._isFullscreen = value; }
        }

        public bool VSyncActivated
        {
            get { return this._vSyncActivated; }
            set { this._vSyncActivated = value; }
        }

        public Vector2 BallDefaultPosition
        {
            get { return new Vector2((int)this._screenWidth / 2, (int)this._screenHeight /4); }
            // The default position of the ball, it is the center of a third of the screen            
        }
    }
}
